package com.zhz.lib.project.service.libnews;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhz.lib.project.ibatis.dao.libnews.LibnewsDAO;
import com.zhz.lib.project.ibatis.domain.libnews.Libnews;
import com.zhz.lib.project.vo.libnews.LibnewsVO;

/**
 * @author LiWei <a href="mailto:liwei2672@gmail.com">liwei2672@gmail.com</a>
 * @version 创建时间：2010-5-2 下午08:42:32
 * 
 */
@Service
public class LibnewsService {
    private static Logger logger     = Logger.getLogger(LibnewsService.class);
    @Autowired
    private LibnewsDAO    libnewsDAO;
    //首页显示的标题长度
    private static int    MAX_LENGTH = 29;

    /**
     * 根据ID获取消息
     * 
     * @param hotlinkVO
     * @return
     */
    public LibnewsVO getLibnewsById(int id) {

        Libnews libnews = libnewsDAO.getLibnewsById(id + "");
        LibnewsVO libnewsVO = new LibnewsVO();
        BeanUtils.copyProperties(libnews, libnewsVO);
        libnewsDAO.hitPlusOne(id + "");
        return libnewsVO;
    }

    public List<LibnewsVO> getLatestLibnewsBySortType(int firstResult, int maxResults,
                                                      String sortType) {
        List<Libnews> libnewsList = libnewsDAO.getLatestLibnewsBySortType(firstResult, maxResults,
            sortType);
        return LibnewsUtil.ConvertTitle(libnewsList, MAX_LENGTH);
    }

}
